﻿<?xml version="1.0" encoding="utf-8" ?>

<cls:class
	name="CdfsFileReader"
	type="http://metalx.org/Storage/Files/Cdfs/CdfsFileReader"
	xmlns="http://metalx.org/Program"
	xmlns:dbg="http://metalx.org/i386/Functions/Debug"
	xmlns:lst="http://metalx.org/i386/Functions/List"
	xmlns:con="http://metalx.org/i386/Functions/Console"
	xmlns:int="http://metalx.org/i386/Functions/Integer"
	xmlns:byte="http://metalx.org/i386/Functions/Byte"
	xmlns:bool="http://metalx.org/i386/Functions/Boolean"
	xmlns:str="http://metalx.org/i386/Functions/String"
	xmlns:clsf="http://metalx.org/i386/Functions/Class"
	xmlns:mm="http://metalx.org/i386/Functions/MemoryManager"
	xmlns:var="http://metalx.org/Variable"
	xmlns:sys="http://metalx.org/i386/Functions/System"
	xmlns:cat="http://metalx.org/i386/Functions/Catalog"
	xmlns:obj="http://metalx.org/i386/Functions/Object"
	xmlns:fd="http://metalx.org/i386/Functions/FloppyDrive"
	xmlns:asc="http://metalx.org/Ansi/Ascii"
	xmlns:ari="http://metalx.org/Intel/80386/Arithmetic"
	xmlns:logic="http://metalx.org/Intel/80386/Logic"
	xmlns:math="http://metalx.org/Intel/80386/Math"
	xmlns:shift="http://metalx.org/Intel/80386/Shift"
	xmlns:imm="http://metalx.org/Intel/80386/Immediate"
	xmlns:inc="http://metalx.org/Intel/80386/Increment"
	xmlns:index="http://metalx.org/Intel/80386/Index"
	xmlns:cpu="http://metalx.org/Intel/80386/Operators"
	xmlns:op="http://metalx.org/Intel/80386/Operands"
	xmlns:cls="http://metalx.org/Class">

	<cls:field name="File" offset="0" type="http://metalx.org/Reference"/>
	<cls:field name="Position" offset="4" type="http://metalx.org/Integer"/>

	<cls:method name="Create" type="http://metalx.org/Storage/Files/Cdfs/CdfsFileReader" static="true">
		<cls:parameter name="File" type="http://metalx.org/Storage/Files/Cdfs/CdfsFile"/>

		<mm:CheckOut length="8"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIAddress/>

		<cpu:CopyImmediateToOperandFunction/>
		<imm:CopyImmediateToDIAddressPlusImmediate8/>
		<byte>4</byte>
		<int>0</int>

		<obj:Create/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>4</byte>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="SetPosition" type="http://metalx.org/Storage/Files/Cdfs/CdfsFileReader">
		<cls:parameter name="Position" type="http://metalx.org/Integer"/>

		<cpu:PushDIToStack/>

		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:SI-SIAddress/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:SI-SIAddress/>

		<obj:ExecuteMethod name="SetPosition"/>

		<cpu:PullDIFromStack/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Skip" type="http://metalx.org/Storage/Fdc/FdcFloppyDriveReader">
		<cls:parameter name="Position" type="http://metalx.org/Integer"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-BPAddressPlusImmediate8/>
		<byte>0</byte>

		<obj:GetData/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:BX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:AddRegisterToOperand/>
		<op:BX-AXRegister/>

		<cpu:DecrementAX/>
		<cpu:DecrementBX/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftBXRegisterRight/>
		<byte>9</byte>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterRight/>
		<byte>9</byte>

		<cpu:CompareRegisterToOperand/>
		<op:AX-BXRegister/>

		<cpu:BranchToRelative8IfEqual/>
		<addressOf ref="sameBlock" type="Relative8"/>

		<cpu:CallRelative/>
		<addressOf ref="readBlock" type="Relative32"/>

		<label id="sameBlock"/>

		<cpu:CallRelative/>
		<addressOf ref="readBlock" type="Relative32"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToBPRegister/>
		<byte>4</byte>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadBytes" type="http://metalx.org/List">
		<cls:parameter name="Count" type="http://metalx.org/Integer"/>

		<cpu:CopyImmediateToDI/>
		<int>0</int>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadBoolean" type="http://metalx.org/Boolean">
		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<bool:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadByte" type="http://metalx.org/Byte">
		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<byte:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadShort" type="http://metalx.org/Short">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<mm:CheckOut length="2"/>

		<cpu:PushDIToStack/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddress/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:PullDIFromStack/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-DIAddressPlusImmediate8/>
		<byte>1</byte>

		<obj:Create length="2" type="http://metalx.org/Short"/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadInteger" type="http://metalx.org/Integer">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<mm:CheckOut length="4"/>

		<cpu:PushDIToStack/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddress/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>1</byte>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>2</byte>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:PullDIFromStack/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-DIAddressPlusImmediate8/>
		<byte>3</byte>

		<obj:Create length="4" type="http://metalx.org/Integer"/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadFloat" type="http://metalx.org/Float">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<mm:CheckOut length="4"/>

		<cpu:PushDIToStack/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddress/>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>1</byte>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:CopyOperandToRegister/>
		<op:SI-IndexAddress/>
		<index:SP/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>2</byte>

		<cpu:CallRelative/>
		<addressOf ref="readByte" type="Relative32"/>

		<cpu:PullDIFromStack/>

		<cpu:CopyRegisterToOperand8/>
		<op:AL-DIAddressPlusImmediate8/>
		<byte>3</byte>

		<obj:Create length="4" type="http://metalx.org/Float"/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadDouble" type="http://metalx.org/Double">
		<cpu:CopyImmediateToDI/>
		<int>0</int>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadReal" type="http://metalx.org/Real">
		<cpu:CopyImmediateToDI/>
		<int>0</int>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ReadString" type="http://metalx.org/String">
		<cls:parameter name="Count" type="http://metalx.org/Integer"/>

		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:SI-SIAddress/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:SI-SIAddress/>

		<obj:ExecuteMethod name="ReadString"/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ToString" type="http://metalx.org/String">
		<cpu:CopyImmediateToDI/>
		<addressOf ref="className" type="Absolute32"/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<var:string id="className">Cdfs File Reader</var:string>
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class" static="true">
		<cpu:CopyRegisterToOperand/>
		<op:BX-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
</cls:class>